package cn.alusiaor.eurekaclientuserservice.config;

import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static cn.alusiaor.eurekaclientuserservice.filters.LogFilter.KEY_LOG;

/**
 * @Author: zhuzhiping
 * @Description:
 * @Date: 2020/12/28 11:18
 */

@Configuration
@Slf4j
public class FeignInterceptorConfig {

    @Bean
    public RequestInterceptor requestInterceptor() {
        RequestInterceptor requestInterceptor = template -> {
            String traceId = MDC.get(KEY_LOG);
            log.info("日志requestId");
            template.header(KEY_LOG, traceId);
        };
        return requestInterceptor;
    }
}
